
package com.tools.ad.util;

import android.content.Context;
import android.graphics.Typeface;

public class FontUtils {

    private static FontUtils mInstance;
    private Context mCtx;
    private Typeface mRobotoMedium;
    private Typeface mRobotoLight;
    private Typeface mRobotoRegular;
    private Typeface mRobotoThin;

    private static final String FONT_ROBOTO_MEDIUM_ASSERT_PATH = "fonts/Roboto-Medium.ttf";
    private static final String FONT_ROBOTO_LIGHT_ASSERT_PATH = "fonts/Roboto-Light.ttf";
    private static final String FONT_ROBOTO_REGULAR_ASSERT_PATH = "fonts/Roboto-Regular.ttf";
    private static final String FONT_ROBOTO_THIN_ASSERT_PATH = "fonts/Roboto-Thin.ttf";

    private FontUtils(Context ctx) {
//        mCtx = ctx.getApplicationContext();
//        mRobotoMedium = Typeface.createFromAsset(ctx.getAssets(), FONT_ROBOTO_MEDIUM_ASSERT_PATH);
//        mRobotoLight = Typeface.createFromAsset(ctx.getAssets(), FONT_ROBOTO_LIGHT_ASSERT_PATH);
//        mRobotoRegular = Typeface.createFromAsset(ctx.getAssets(), FONT_ROBOTO_REGULAR_ASSERT_PATH);
//        mRobotoThin = Typeface.createFromAsset(ctx.getAssets(), FONT_ROBOTO_THIN_ASSERT_PATH);
    }

    public static FontUtils getInstance(Context ctx) {
        if (mInstance == null) {
            synchronized (FontUtils.class) {
                if (mInstance == null) {
                    mInstance = new FontUtils(ctx);
                }
            }
        }
        return mInstance;
    }

    public Typeface getRobotoMedium() {
        if (isEnglish()) {
            return mRobotoMedium;
        } else {
            return null;
        }
    }

    public Typeface getRoboLight() {
        if (isEnglish()) {
            return mRobotoLight;
        } else {
            return null;
        }
    }

    public Typeface getRobotRegular() {
        if (isEnglish()) {
            return mRobotoRegular;
        } else {
            return null;
        }
    }

    public Typeface getRobotThin() {
        if (isEnglish()) {
            return mRobotoThin;
        } else {
            return null;
        }
    }

    public boolean isEnglish() {
        try {
            String lan = mCtx.getResources().getConfiguration().locale.toString();
            if (lan.startsWith("en")) {
                return true;
            }
        } catch (Exception e) {
        }
        return false;
    }
}
